package com.demo;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
//在配置过这个注解后，服务启动会自动注册到 Eureka Server
@EnableEurekaClient
//开启服务发现
@EnableDiscoveryClient
//开启熔断开关
@EnableCircuitBreaker
public class Springcloud02ProviderDept8081Application {

	public static void main(String[] args) {
		SpringApplication.run(Springcloud02ProviderDept8081Application.class, args);
	}

	/**
	 * 增加一个 Dashboard 的 Bean
	 * 固定的代码
	 */
	@Bean
	public ServletRegistrationBean HystrixMetricsStreamServlet(){
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
		//添加路径
		registrationBean.addUrlMappings("/actuator/hystrix.stream");
		return registrationBean;
	}
}
